﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using MVCWeb.Models;
using System.Web.Mvc;
using System.Web.Routing;

namespace MVCWeb.Helpers
{
    public static class MenuHelper
    {
        //public static string UserMenu(this HtmlHelper helper)
        //{
        //    string menuString = string.Empty;
        //    try
        //    {
        //        // Get community by login user.
        //        HOACRMDataContext dc = new HOACRMDataContext();
        //        MembershipUser membershipUser = Membership.GetUser();
        //        Guid membershipId = new Guid(membershipUser.ProviderUserKey.ToString());
        //        MVCWeb.Models.User user = dc.Users.Where<MVCWeb.Models.User>(u => u.MembershipId == membershipId).First<MVCWeb.Models.User>();
        //        Community community = dc.Communities.Where<Community>(c => c.UserId == user.UserId || c.ManagerId == user.UserId).First<Community>();
        //        int communityId = community.CommunityId;

        //        Guid id = Guid.NewGuid();
        //        menuString = "<br /><ul id='csddm'>";
        //        menuString += string.Format("<li><a href='{0}' onmouseover=\"mopen('{2}')\" onmouseout=\"mclosetime()\">{1}</a>", Url.Action("List", "Community"), "Home", id.ToString());
        //        menuString += string.Format("<div id='{0}' onmouseover='mcancelclosetime()' onmouseout='mclosetime()'>", id);
        //        menuString += "</div></li>";
        //        IQueryable<MVCWeb.Models.Menu> menus = new MVCWeb.Models.HOACRMDataContext().Menus.Where<MVCWeb.Models.Menu>(m => m.CommunityId == (int)ViewData["CommunityId"]).OrderBy(m => m.SortOrder).ThenBy(m => m.MenuName);
        //        if (menus != null)
        //        {

        //            IQueryable<MVCWeb.Models.Menu> topmenu = menus.Where<MVCWeb.Models.Menu>(m => m.Type == "CommunityMenu" && m.ParentMenuId == 0).OrderBy(m => m.SortOrder).ThenBy(m => m.MenuName);

        //            foreach (var tm in topmenu)
        //            {
        //                string correctLink = tm.Link;
        //                string[] link = tm.Link.Split('/');
        //                if (!correctLink.StartsWith("http") && link.Length > 1)
        //                    correctLink =  Url.Action(link[1], link[0], new RouteValueDictionary(new { id = link[2] }));
        //                Guid divid = Guid.NewGuid();
        //                menuString += string.Format("<li><a href='{0}' onmouseover=\"mopen('{2}')\" onmouseout=\"mclosetime()\">{1}</a>", correctLink, tm.MenuName, divid.ToString());
        //                menuString += string.Format("<div id='{0}' onmouseover='mcancelclosetime()' onmouseout='mclosetime()'>", divid);
        //                foreach (var sm in menus.Where(m => m.ParentMenuId == tm.MenuId))
        //                {
        //                    correctLink = sm.Link;
        //                    link = sm.Link.Split('/');
        //                    if (!correctLink.StartsWith("http") && link.Length > 1)
        //                        correctLink = Url.Action(link[1], link[0], new RouteValueDictionary(new { id = link[2] }));
        //                    menuString += string.Format("<a href='{0}'>{1}</a>", correctLink, sm.MenuName);
        //                }
        //                menuString += "</div></li>";
        //            }
        //        }
        //        menuString += "</ul>";

        //        menuString = menuString.Replace("[@id]", ViewData["CommunityId"].ToString());
        //    }
        //    catch {}
        //    finally
        //    {
        //        menuString += "<br /><br />";
        //    }
        //}

        //public static string AdminMenu(this HtmlHelper helper, string id, string url, string alternateText)
        //{

        //}
    }
}
